package dhadi.util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

import dhadi.model.Move;

public class MoveWriter {
	private Writer out;
	
	public MoveWriter(File file) throws IOException {
		out = new FileWriter(file);
	}
	
	public void write(Move move) {
		if (move == null) return;
		try {
			out.write(move.toJson().toString());
			out.write("\n");
			out.flush();
		} catch (Exception e) {
			Logger.log(MoveWriter.class, "Exception writing move, "+e.getMessage(),e);
		}
	}
	
	public void close() {
		if (out != null)
			try {
				out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
	}
}